package cn.pink.gamesrv;

import cn.pink.core.CallPoint;
import cn.pink.core.NodeType;
import cn.pink.core.Port;
import cn.pink.core.Service;
import cn.pink.core.gen.proxy.DistrClass;
import cn.pink.core.gen.proxy.DistrMethod;
import cn.pink.gamesrv.human.HumanGlobal;
import cn.pink.gamesrv.human.HumanObjectService;

/**
 * @Author: pink
 * @Date: 2022/6/21 16:50
 */
@DistrClass(nodeType = NodeType.GAME, importClass = {CallPoint.class})
public class GameService extends Service {
    public GameService(Port port) {
        super(port);
    }

    @Override
    public Object getId() {
        return RPCProxy.GameServiceProxy.DIST_NAME;
    }

    @DistrMethod
    public void defaultHandler(String str) {

    }

    @DistrMethod
    public void roleLogin(CallPoint sessionPoint, String humanId, String userIdentity, String token) {
        //先判断下本服上有没有HumanObjectService
        HumanObjectService service = getPort().getService(humanId);
        if(service != null) {
            //有直接复用之前的human. 更改sessionPoint, 不然玩家换gate回不去消息.
            service.changeSessionPoint(sessionPoint);

            port.returns();
            return;
        }

        HumanObjectService humanObjServ = new HumanObjectService(port);
        humanObjServ.login(sessionPoint, humanId, userIdentity, token);
        HumanGlobal.register(humanObjServ);

        port.returns();
    }
}
